package com.example.rabbitmq.demo1_modes.producer.mode02_work;

import com.example.rabbitmq.enums.RabbitmqQueueNamesEnum;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.Date;
import java.util.Scanner;

/**
 * @Author songyahui
 * @Date 2023/7/7 8:14
 * @Description
 */
public class WorkQueueProducer {

    public static void buildMessage(Channel channel) throws IOException {
        channel.queueDeclare(RabbitmqQueueNamesEnum.QUEUE_NAME_WORK.queueName, true, false, false, null);
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            channel.basicPublish("", RabbitmqQueueNamesEnum.QUEUE_NAME_WORK.queueName, MessageProperties.PERSISTENT_TEXT_PLAIN, scanner.next().getBytes());
            System.out.println("发送时间：" + new Date().toString());
        }
    }
}
